package homework.view;


import java.awt.GridLayout;
import java.awt.TextArea;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneLayout;
import javax.swing.table.DefaultTableModel;

import homework.entity.Mypackage;
import homework.entity.User;

public class QueryFrame extends JFrame{
	JLabel l_name,l_category;
    JTextField t_name;
    JButton b_query;
    JTable table_book;
    JComboBox<String> c_category;
    User u;
    public QueryFrame(User user) {
		setTitle("快递物流平台-用户物流信息页面");
		setSize(1000,500);
		setLocation(500,300);
		init(user);
		setVisible(true);
		
	}
    void init(User user) {
    	
		Object[] title = {"编号","千里数","重量","类型","始发地","寄件人","收件人","目的地","价格"};
		Object[][] objectArray = new Object[user.getList().size()][9];

        for (int i = 0; i < user.getList().size(); i++) {
            Mypackage mypackage = user.getList().get(i);
            objectArray[i][0] = mypackage.getId();
            objectArray[i][1] = mypackage.getKilometer();
            objectArray[i][2] = mypackage.getWeigth();
            objectArray[i][3] = mypackage.getType();
            objectArray[i][4] = mypackage.getOrigin();
            objectArray[i][5] = mypackage.getSender();
            objectArray[i][6] = mypackage.getRecipient();
            objectArray[i][7] = mypackage.getDestination();
            objectArray[i][8] = mypackage.getPrice();
        }

		DefaultTableModel d = new DefaultTableModel(objectArray,title);
		JTable jTable = new JTable(d);
		JScrollPane jScrollPane = new JScrollPane(jTable);
		jScrollPane.setBounds(5, 5, 950, 350);
		
		JPanel Panel= new JPanel();
		Panel.setLayout(new BoxLayout(Panel, BoxLayout.Y_AXIS));
		Panel.add(jScrollPane); //添加到滚动面板
		
		
		JScrollPane js2;
		TextArea area=new TextArea();
		for(Mypackage u:user.getList()) {
			area.append("id:"+u.getId()+"\t 详细信息：");
			for(String s :u.getLogisticslist()) {
				area.append(""+s+"\n");
			}
			area.append("\n");
		}
		js2 = new JScrollPane(area);
		js2.setBounds(5,360,950,360);
	    Panel.add(js2);
	    
	    add(Panel);
	    
	}
	


}


